package lablayer.model.MathComponents;

import lablayer.model.ComponentFactory;
import lablayer.model.Componentable;
import lablayer.model.LabData;

/**
 * @author Darkness
 */

class StandardAMSError implements MathComponent {
    private LabData result;

    private LabData data;

    private String componentName = "Стандартная ошибка среднего арифметического выборки";

    private String componentId = "5";

    @Override
    public LabData getData() {
        return this.data;
    }

    @Override
    public void calculate() {
        Double value = 0.0;
        Double sqrtLength = 0.0;
        Double S = 0.0;

        Componentable standardDeviation = ComponentFactory.createComponent(
            MathComponentFactory.createStandardDeviation());
        standardDeviation.setData(this.data);
        standardDeviation.calculate();
        S = (standardDeviation.getResult().getData())[0][0][0];
        sqrtLength = Math.sqrt(((this.data.getData())[0][0]).length);
        value = S / sqrtLength;
        this.result = new LabData(LabData.parseString(value.toString()));
    }

    @Override
    public void setData(LabData data) {
        if (data != null) {
            this.data = data;
        } else {
            throw new NullPointerException("Null pointer data");
        }
    }

    @Override
    public String getComponentId() {
        return this.componentId;
    }

    @Override
    public String getComponentName() {
        return this.componentName;
    }

    @Override
    public LabData getResult() {
        return this.result;
    }

	@Override
	public void setParameter(String params, String values) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public LabData getInitData() {
		throw new UnsupportedOperationException("Not supported yet.");
	}
}
